import pandas as pd
import numpy as np
import gen3
import openpyxl
import plotly.express as px
import requests
import json
import plotly
import plotly.io as pio
from pandas.core.common import SettingWithCopyWarning
import warnings
warnings.simplefilter(action="ignore", category=SettingWithCopyWarning)
plotly.offline.init_notebook_mode()
state_abbrev = {
"Alabama": "AL", "Alaska": "AK", "Arizona": "AZ", "Arkansas": "AR", "California": "CA", "Colorado": "CO",
"Connecticut": "CT", "Delaware": "DE", "Florida": "FL", "Georgia": "GA", "Hawaii": "HI", "Idaho": "ID",
"Illinois": "IL", "Indiana": "IN", "Iowa": "IA", "Kansas": "KS", "Kentucky": "KY", "Louisiana": "LA",
"Maine": "ME", "Maryland": "MD", "Massachusetts": "MA", "Michigan": "MI", "Minnesota": "MN",
"Mississippi": "MS", "Missouri": "MO", "Montana": "MT", "Nebraska": "NE", "Nevada": "NV",
"New Hampshire": "NH", "New Jersey": "NJ", "New Mexico": "NM", "New York": "NY", "North Carolina": "NC",
"North Dakota": "ND", "Ohio": "OH", "Oklahoma": "OK", "Oregon": "OR", "Pennsylvania": "PA",
"Rhode Island": "RI", "South Carolina": "SC", "South Dakota": "SD", "Tennessee": "TN", "Texas": "TX",
"Utah": "UT", "Vermont": "VT", "Virginia": "VA", "Washington": "WA", "West Virginia": "WV",
"Wisconsin": "WI", "Wyoming": "WY", "District of Columbia": "DC", "American Samoa": "AS", "Guam": "GU",
"Northern Mariana Islands": "MP", "Puerto Rico": "PR", "United States Minor Outlying Islands": "UM",
"U.S. Virgin Islands": "VI"}
policyMap = {0: 'Not Approved', 1:'Approved'}
waiverMap = {'.': 0, 0:0, 1:1}
def clean_fips(overdose_df):
for i in range(len(overdose_df['County Code'])):
if len(overdose_df['County Code'].iloc[i]) < 5:
overdose_df['County Code'].iloc[i] = '0' + overdose_df['County Code'].iloc[i]
if len(overdose_df['State Code'].iloc[i]) < 2:
overdose_df['State Code'].iloc[i] = '0' + overdose_df['State Code'].iloc[i]
return overdose_df
!gen3 drs-pull object dg.6VTS/5200158e-e9fe-44ef-96c9-e89ecd402fc4
!gen3 drs-pull object dg.6VTS/2b83e419-8d3d-4569-b9a1-a52ecd387cba
!gen3 drs-pull object dg.6VTS/a0a8785a-8663-47b9-95ea-a1813612a2f1
!gen3 drs-pull object dg.6VTS/abe9cd49-fc86-4c9b-b9d0-f8c0280d8aaa
!gen3 drs-pull object dg.6VTS/b7974ffe-2e46-47cf-9d57-4d8900d7a40f
!gen3 drs-pull object dg.6VTS/dca15d95-aac5-4879-88cb-3a740398f26c
opioidOverdoses = pd.read_csv('data/Opioid_Overdoses_03082022.tsv', sep='\t')
df1 = pd.read_excel('../../BRH/contentCreation/data/jcoin-pdaps/buprenorphine-and-methadone-during-covid-19-data-020222.xlsx')
df2 = pd.read_excel('../../BRH/contentCreation/data/jcoin-pdaps/covid-19-state-medicaid-waivers-data-020222.xlsx')
df3 = pd.read_excel('../../BRH/contentCreation/data/jcoin-pdaps/covid-19-moud-at-state-correctional-facilities-data-020222.xlsx')
opioidOverdoses = opioidOverdoses.drop(['Notes', 'Year Code'], axis=1)
opioidOverdoses = opioidOverdoses[opioidOverdoses['State'].notna()]
opioidOverdoses = opioidOverdoses[opioidOverdoses['Deaths'] != 'Missing']
opioidOverdoses = opioidOverdoses.astype({'County Code': 'int32', 'Year': 'int32',
'Deaths': 'int32', 'Population': 'int32',
'State Code': 'int32'})
opioidOverdoses = opioidOverdoses.astype({'County Code': 'str', 'State Code': 'str'})
opioidOverdoses = opioidOverdoses.sort_values(by=['Year', 'County Code']).reset_index(level=None)
opioidOverdoses = clean_fips(opioidOverdoses)
opioidOverdoses2019 = opioidOverdoses[opioidOverdoses['Year'] == 2019]
opioidOverdoses2020 = opioidOverdoses[opioidOverdoses['Year'] == 2020]
opioidState2019 = opioidOverdoses2019.groupby('State')['Deaths'].sum().reset_index()
opioidState2019['Population'] = opioidOverdoses2019.groupby('State')['Population'].sum().reset_index()['Population']
opioidState2019['Crude Rate'] = (opioidState2019['Deaths']/opioidState2019['Population'])*(10**5)
opioidState2019['Crude Rate'] = opioidState2019['Crude Rate'].round(decimals=2)
opioidState2020 = opioidOverdoses2020.groupby('State')['Deaths'].sum().reset_index()
opioidState2020['Population'] = opioidOverdoses2020.groupby('State')['Population'].sum().reset_index()['Population']
opioidState2020['Crude Rate'] = (opioidState2020['Deaths']/opioidState2020['Population'])*(10**5)
opioidState2020['Crude Rate'] = opioidState2020['Crude Rate'].round(decimals=2)
opioidState2020['Rate Percent Increase'] = (100*(opioidState2020['Crude Rate'] - opioidState2019['Crude Rate'])/opioidState2019['Crude Rate']).round(decimals=2)
opioidState2020['Abbreviations'] = opioidState2020['State'].map(state_abbrev)
df1['Policy Change'] = ((df1['Telehealth_existing_bup'] + df1['Telehealth_existing_methadone']) != 0).astype(int)
df1['Policy'] = 'Telehealth MOUD Treatment'
df1 = df1[['Jurisdictions', 'Policy Change', 'Policy']]
df2['Policy Change'] = df2['JM_15sud'].map(waiverMap)
df2['Policy'] = 'SUD Medicaid Waiver'
df2 = df2[['Jurisdictions', 'Policy Change', 'Policy']]
df3['Policy Change'] = df3['JC_MOUDlaw']
df3['Policy'] = 'MOUD Treatment While Incarcerated'
df3 = df3[['Jurisdictions', 'Policy Change', 'Policy']]
df = pd.concat([df1, df2, df3],ignore_index=True)
df['Abbreviations'] = df['Jurisdictions'].map(state_abbrev)
df['Change In Policy'] = df['Policy Change'].map(policyMap)
df = df[['Jurisdictions', 'Abbreviations', 'Change In Policy', 'Policy']]
merged_df = df.merge(opioidState2020, how='outer', on=['Abbreviations'])[['Jurisdictions', 'Abbreviations',
'Change In Policy', 'Policy', 'Deaths',
'Population', 'Crude Rate', 'Rate Percent Increase']]
approved_df = merged_df[merged_df['Change In Policy'] == 'Approved']
not_approved_df = merged_df[merged_df['Change In Policy'] == 'Not Approved']
We will be investigating data on the statewide increases in opioid overdose deaths during the early stages of the COVID-19 pandemic and corresponding statewide changes in public health policy related to opioid use disorder treatment.
The opioid overdose mortality data for 2019 and 2020 comes from the CDC WONDER mortality dataset; using the multiple cause of death codes T40.0 (Opium), T40.1 (Heroin), T40.2 (Natural opioid analgesics), T40.3 (Methadone), T40.4 (Synthetic opioid analgesics other than methadone), and T40.6 (Other unspecified narcotics).
The data on statewide changes to opioid treatment policy during the COVID-19 pandemic are from NIDA-PDAPS hosted on the JCOIN data commons. In particular the datasets:
In the following two images we can see the nation wide impact of the opioid epidemic. The first image is for the crude mortality rate (deaths/population) per 100 thousand residents. The second image is the percent increase in each state's mortality rate.
fig = px.choropleth(opioidState2020, locations='Abbreviations', locationmode="USA-states",
color='Crude Rate',range_color=(0, 40), labels={'Crude Rate': 'Mortality Rate per 100K'},
title='2020 Recorded Opioid Overdoses Mortality Rate', color_continuous_scale='purp', scope="usa")
fig.show()
Listed below are the five regions with the highest mortality rates.
opioidState2020.sort_values(by=['Crude Rate'], ascending=False, ignore_index=True).head()
| State | Deaths | Population | Crude Rate | Rate Percent Increase | Abbreviations | |
|---|---|---|---|---|---|---|
| 0 | West Virginia | 1064 | 1375557 | 77.35 | 305.61 | WV |
| 1 | District of Columbia | 335 | 712816 | 47.00 | 35.41 | DC |
| 2 | Kentucky | 1430 | 3123038 | 45.79 | 44.86 | KY |
| 3 | Maryland | 2530 | 6007758 | 42.11 | 19.19 | MD |
| 4 | Delaware | 404 | 986809 | 40.94 | 3.54 | DE |
fig = px.choropleth(opioidState2020, locations='Abbreviations', locationmode="USA-states",
color='Rate Percent Increase',range_color=(0, 100), labels={'Crude Rate': 'Mortality Rate per 100K'},
title='2020 Recorded Opioid Overdoses Mortality Rate',color_continuous_scale='purp', scope="usa")
fig.show()
Listed below are the five regions with the highest percent increases in mortality rates. The data for Wyoming is missing because in 2019 no opioid overdose deaths were recorded using the CDC MCD codes. Additionally, the percent increase in overdose deaths may be artificailly inflated in some states due to changes in how each state records opioid overdose deaths.
opioidState2020.sort_values(by=['Rate Percent Increase'], ascending=False, ignore_index=True).head()
| State | Deaths | Population | Crude Rate | Rate Percent Increase | Abbreviations | |
|---|---|---|---|---|---|---|
| 0 | Tennessee | 2189 | 5661595 | 38.66 | 566.55 | TN |
| 1 | Ohio | 4335 | 10953625 | 39.58 | 370.07 | OH |
| 2 | West Virginia | 1064 | 1375557 | 77.35 | 305.61 | WV |
| 3 | South Carolina | 1338 | 4626946 | 28.92 | 272.20 | SC |
| 4 | Wisconsin | 1149 | 4413768 | 26.03 | 159.00 | WI |
Here we look at three key features for U.S. States. The code name for the policy is listed at the end of each line.
In each of the following two images we will see the opioid overdose mortality rates for states who have approved the above changes in opioid treatment policy during the COVID-19 pandemic.
fig = px.choropleth(approved_df, locations='Abbreviations', locationmode="USA-states",color='Crude Rate',
range_color=(0, 40), animation_frame='Policy', labels={'Crude Rate': 'Mortality Rate per 100K'},
title='2020 Recorded Opioid Overdoses Mortality Rate',color_continuous_scale='purp',scope="usa")
fig.show()
fig = px.choropleth(approved_df, locations='Abbreviations', locationmode="USA-states",color='Rate Percent Increase',
range_color=(0, 100), animation_frame='Policy',labels={'Crude Rate': 'Mortality Rate per 100K'},
title='2020 Recorded Opioid Overdoses Mortality Rate',color_continuous_scale='purp',scope="usa")
fig.show()